WAFFLE CONTENT

OVERVIEW OF ASSIGNMENT

For this assignment, I decided to take a break from trying to show statistically-significant sad things about New Mexico and Mattapan, and make a very important map about the walksheds and bikesheds of places one could order waffles in Cambridge.

Housekeeping & Setup

Libraries

Attempt to Load Image {{r, message = FALSE, results='hide'} # Tried to add an image, but no dice. #![],("C:\Users\sageg\Desktop\svoorhees-quant\waffles_donkey.jpg")

OSM Setup: Ran Once

opq(bbox = 'Cambridge, MA USA') %>%
  add_osm_feature(key = 'highway') %>%
  osmdata_xml(file = 'OTP/graphs/default/cambridge_streets.osm')

Load Cambridge Streets

MA_state_plane <- "+proj=lcc +lat_1=41.71666666666667 +lat_2=42.68333333333333 +lat_0=41 +lon_0=-71.5 +x_0=200000 +y_0=750000 +ellps=GRS80 +units=m +no_defs"

cambridge_street_features <- opq(bbox = 'Cambridge MA USA') %>%
  add_osm_feature(key = 'highway') %>%
  osmdata_sf()

cambridge_streets <- cambridge_street_features$osm_lines %>%
  st_transform(crs = MA_state_plane)

Plot Cambridge Streets

ggplot(cambridge_streets) +
  geom_sf() +
  theme_map()

^ I would take big money bets that there is a tote bag with this on there somewhere in Cambridge.

Open Trip Planner

Conntect to Open Trip Planner

Ran Once path_otp <- otp_dl_jar(“OTP”)

path_data <- file.path(getwd(), "OTP")
path_otp <- paste(path_data, "otp.jar",sep = "/")

otp_build_graph(otp = path_otp, dir = path_data, memory = 1024)
otp_setup(otp = path_otp, dir = path_data, memory =1024)
otpcon <- otp_connect()

Create Waffle Address List

waffle_address_list = c("1154 Massachusetts Ave, Cambridge, MA",
                        "912 Massachusetts Ave, Cambridge, MA",
"441 Cambridge St, Cambridge, MA 02141",
"3 Beacon St, Somerville, MA",
"450 Massachusetts Ave, Cambridge, MA",
"1334 Cambridge St, Cambridge, MA")
points <- geo(address = waffle_address_list, mode = "batch") 
head(points)
points <- st_as_sf(x = points,                         
           coords = c("long", "lat"),
           crs = 4326)

Find Isochrones

waffle_points_10min_walk <- 
  otp_isochrone(otpcon = otpcon, fromPlace = points, 
                mode = "WALK", cutoffSec = 600) %>%
 st_transform(crs = MA_state_plane) %>%
  mutate(mode = "walk")

waffle_points_10min_bike <- 
  otp_isochrone(otpcon = otpcon, fromPlace = points, 
                mode = "BICYCLE", cutoffSec = 600)%>%
 st_transform(crs = MA_state_plane) %>%
  mutate(mode = "bike")

iso_all_modes <- rbind(waffle_points_10min_walk, waffle_points_10min_bike)

Walksheds of Cambridge Waffles

Pretty close to full coverage, but definitely seeing some waffle-deserts.

ggplot(waffle_points_10min_walk) +
  annotation_map_tile(zoomin = 1, progress = "none") +
  geom_sf(fill ="yellowgreen", alpha=0.2) +
  theme_map() 
## Loading required namespace: raster

Bikesheds of Cambridge Waffles

They did it! The free market provided waffles within biking distance of all of Cambridge!

ggplot(waffle_points_10min_bike) +
  annotation_map_tile(zoomin = 1, progress = "none") +
  geom_sf(fill ="sienna", alpha=0.4) +
  theme_map() 

Combined!

If you look at it right, looks like a waffle with a butter pad to me.
Could that be accidental? Isn’t it more likely part of a plan??

right_side <- st_bbox(iso_all_modes)$xmax
left_side  <- st_bbox(iso_all_modes)$xmin
top_side <- st_bbox(iso_all_modes)$ymax
bottom_side <- st_bbox(iso_all_modes)$ymin

ggplot(iso_all_modes) +
  geom_sf(data = cambridge_streets, color = "grey") +
  geom_sf(aes(fill = mode), color =NA, alpha = 0.5) +
  geom_sf(data = points)+
  coord_sf(xlim = c(left_side, right_side), 
           ylim = c(bottom_side, top_side), expand = FALSE) +
  scale_fill_viridis_d(name = "Area that is reachable within 10 minutes", labels = c("By Foot", "By Bike")) +
  theme_map() 

Count the number of libraries within a 10 minute walk of Waffles

CPL_libraries <- st_read( 
  "https://data.cambridgema.gov/api/geospatial/kn2z-b6eg?method=export&format=KML", quiet =TRUE) %>%
  st_transform(crs = MA_state_plane) 

Cambridge_public_schools <- st_read("https://data.cambridgema.gov/api/geospatial/jhbq-dj88?method=export&format=KML", quiet =TRUE)

Library Scores for our Waffle houses

Its important to know in my analysis, where one could go get waffles and then go to a public library. Nothing helps digestion like publicly available civic resources.
Fortunately for us, 3 of our waffle establishment are well connected.

waffle_points_10min_walk <- waffle_points_10min_walk %>%
  mutate(library_score = lengths(st_covers(geometry, CPL_libraries)))
ggplot(waffle_points_10min_walk) +
  annotation_map_tile(zoomin = 1, progress = "none") +
   scale_fill_distiller(palette = "Spectral")+
  geom_sf(aes(fill=library_score), alpha=.5) +
  theme_map() 

Area difference of Isochrones

iso_areas <- iso_all_modes %>%
  mutate(area = st_area(iso_all_modes)) %>%
  st_set_geometry(NULL) %>%
  pivot_wider(names_from = mode, values_from = area) 

ggplot(iso_areas, 
       aes(x = as.numeric(walk), y = as.numeric(bike))) +
  geom_point() +
  scale_x_continuous(name = 
            "Area within a ten-minute walking distance\nof a waffles\n(square km)") +
  scale_y_continuous(name = 
            "Area within a five-minute biking distance\nof a waffles\n(square km)") +
  theme_bw()

CLOSE OTP for Cambridge

otp_stop()
## [1] "SUCCESS: The process \"java.exe\" with PID 40104 has been terminated."

NON-WAFFLE CONTENT –Not part of assignment

Leaving this code here for my future reference, but no need to grade beyond this point!

Create ISOCHROMES LIBRARIES (copied from Carole’s COde)

{r, message = FALSE, results=‘hide’} iso_5min_walk <- otp_isochrone(otpcon = otpcon, fromPlace = CPL_libraries, mode = “WALK”, cutoffSec = 300) %>% st_transform(crs = MA_state_plane) %>% mutate(mode = “walk”)

iso_5min_drive <- otp_isochrone(otpcon = otpcon, fromPlace = CPL_libraries, mode = “CAR”, cutoffSec = 300) %>% st_transform(crs = MA_state_plane) %>% mutate(mode = “drive”)

iso_all_modes <- rbind(iso_5min_drive, iso_5min_walk)

LOAD Cambridge KML Files

{r, message = FALSE, results=‘hide’} CPL_libraries <- st_read( “https://data.cambridgema.gov/api/geospatial/kn2z-b6eg?method=export&format=KML”)

Cambridge_public_schools <- st_read(“https://data.cambridgema.gov/api/geospatial/jhbq-dj88?method=export&format=KML”)

Plot CP Library Isochrones (Carole’s Code)

{r, message = FALSE, results=‘hide’} right_side <- st_bbox(iso_all_modes)\(xmax left_side <- st_bbox(iso_all_modes)\)xmin top_side <- st_bbox(iso_all_modes)\(ymax bottom_side <- st_bbox(iso_all_modes)\)ymin

ggplot(iso_all_modes) + annotation_map_tile(zoomin = 0, progress = “none”) + geom_sf(aes(fill = mode), alpha = 0.5) + geom_sf(data = CPL_libraries) + coord_sf(xlim = c(left_side, right_side), ylim = c(bottom_side, top_side), expand = FALSE) + scale_fill_viridis_d(name = “Area that is reachable within 5 minutes”, labels = c(“By car”, “By foot”)) + theme_map() + labs(caption = “Basemap Copyright OpenStreetMap contributors”)

CREATE SCHOOL ISOCHRONES (Modeled from Carole’s COde)

{r, message = FALSE, results=‘hide’} iso_5min_walk_school <- otp_isochrone(otpcon = otpcon, fromPlace = Cambridge_public_schools, mode = “WALK”, cutoffSec = 300) %>% st_transform(crs = MA_state_plane) %>% mutate(mode = “walk”)

iso_5min_drive_school <- otp_isochrone(otpcon = otpcon, fromPlace = Cambridge_public_schools, mode = “CAR”, cutoffSec = 300) %>%

st_transform(crs = MA_state_plane) %>% mutate(mode = “drive”)

iso_all_modes_school <- rbind(iso_5min_drive_school, iso_5min_walk_school)

Plot CP Library Isochrones

{r, message = FALSE, results=‘hide’} right_side <- st_bbox(iso_all_modes_school)\(xmax left_side <- st_bbox(iso_all_modes_school)\)xmin top_side <- st_bbox(iso_all_modes_school)\(ymax bottom_side <- st_bbox(iso_all_modes_school)\)ymin

ggplot(iso_all_modes) + annotation_map_tile(zoomin = 0, progress = “none”) + geom_sf(aes(fill = mode), alpha = 0.5) + geom_sf(data = CPL_libraries) + coord_sf(xlim = c(left_side, right_side), ylim = c(bottom_side, top_side), expand = FALSE) + scale_fill_viridis_d(name = “Area that is reachable within 5 minutes”, labels = c(“By car”, “By foot”)) + theme_map() + labs(caption = “Basemap Copyright OpenStreetMap contributors”)

Address of a groccery store

{r, message = FALSE, results=‘hide’} point_A <- geo(address = “90 Hampshire St, Cambridge, MA 02139”) print(point_A)

MAKE ISOCHRONE

{r, message = FALSE, results=‘hide’} point_A_10min_walk <- otp_isochrone(otpcon = otpcon, fromPlace = c(-71.09476, 42.36874), mode = “WALK”, cutoffSec = 600)

PLOT POINT A ISOCHRONE

{r, message = FALSE, results=‘hide’} #Plot Isochrone ggplot(point_A_10min_walk) + annotation_map_tile(zoomin = 1, progress = “none”) + geom_sf(fill =“blue”, alpha=0.2) + theme_map()